package com.ztom.context.support.aware

import com.ztom.beans.factory.support.processor.BeanPostProcessor
import com.ztom.context.ApplicationContext

/**
 * @author ZhangTao
 */
class ApplicationContextAwareProcessor(
    private val applicationContext: ApplicationContext
) : BeanPostProcessor {

    override fun postProcessBeforeInitialization(bean: Any, beanName: String): Any? {
        if (bean is ApplicationContextAware) {
            bean.setApplicationContext(applicationContext)
        }
        return bean
    }

    override fun postProcessAfterInitialization(bean: Any, beanName: String): Any? {
        return bean
    }
}